﻿using Events.EventsInfo;
using UnityEngine;

public class PlayerSwordCatchState:PlayerStateBase
{
    public PlayerSwordCatchState(ControllerBase controller, StateMachineBase stateMachine, 
        string stateName, string animatorParameter) : base(controller, stateMachine, stateName, animatorParameter)
    {
    }
    
    public override void Enter(object param)
    {
        base.Enter(param);
        var info = (ReturnSwordInfo) param;
        
        if (info.returnDir==1&&!SelfController.isFacingRight)//剑在右边，但是玩家面向左边，则翻转
        {
            SelfController.Flip();
        }else if (info.returnDir==-1&&SelfController.isFacingRight)//剑在左边，但是玩家面向右边，则翻转
        {
            SelfController.Flip();
        }
        
        //给一个向后的力
        SelfController.mRigidbody2D.AddForce(new Vector2(info.returnDir * -2, 0), ForceMode2D.Impulse);
    }

    public override void Exit()
    {
        base.Exit();
        //设置为busy防止快速触发move状态
        controller.StartBusy(0.2f);
    }

    public override void Update()
    {
        base.Update();
        //SelfController.SetVelocity(Vector2.zero);
        if (triggerFinish)
        {
            stateMachine.ChangeState(Setting.idle);
        }
    }
    
}